Talk:Level up script
Script not working This isn't working for me, and I have exploited every possible way this code can be used, created and modified. If you are curious: void main() { object oCreature = GetLastPCRest(); int nCurrentL = GetHitDice(oCreature); int nLevelMax = 20; ForceRest(oCreature); while(nCurrentL < nLevelMax) { int nXP = ((nLevelMax*(nLevelMax - 1))/2)*1000; SetXP(oCreature,nXP); } } That was my concluded code, but it's like it wasn't even acknowledging my script.Is there a start code, like a main to say "start up?" ZenWarko (talk) 18:26, July 3, 2016 (UTC) Sincerely ''Zen''' * A couple things. First, what script is this? When does it run? It looks like it might be intended to be an OnPlayerRest event script. There may be issues with doing this as a rest script, but I haven't looked at those in a while. : The big problem with your script is that adding ''XP to a character isn't the same as adding levels to him. Because of that, you have a while loop that likely isn't doing what you want. The loop checks that the PC's level is lower than the desired level and, if not, sets the PC's XP to what would be needed to achieve that level. But, the player doesn't have a chance to actually level up, even though he has the XP that he needs to do so. So, the loop essentially runs forever, assuming the PC doesn't already have the desired level. : Simple suggestion: There really isn't any need for a while loop here. Just use an if and set the XP to the right amount and then leave the script so that the player can level up his toon. : BTW, this is the sort of question that people on the scripting sub-forum of Bioware's NWN boards answer regularly. You may want to post there. - MrZork (talk) 18:58, July 3, 2016 (UTC) :* It looks like this script is a modification of the second script in the article, although it has been modified to be unusable (changed how the PC is obtained, and replaced the "if" with an infinite loop). --The Krit (talk) 19:20, July 3, 2016 (UTC) :* You're right that the scripts really should be checking earned levels instead of taken levels. I've updated the scripts in the article. --The Krit (talk) 20:20, July 3, 2016 (UTC) * Scripts are typically fired in response to events. In your version of the script, you are getting the last PC to rest, suggesting it should be put in your module's OnPlayerRest event. The script in the article gets the last creature to use an object, suggesting (and stated, for that matter) that is should be put in the OnUsed event of a placeable. : That being said, I would not recommend putting your script anywhere in its current form, as it contains an infinite loop. You are looping while nCurrentL < nLevelMax, and your script does nothing to ever change that condition. So the loop goes on until the game enforces the maximum instruction limit. --The Krit (talk) 19:27, July 3, 2016 (UTC)